import type { LoginData } from '@/types/common'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore(
  'user',
  () => {
    const token = ref<string>()
    const userInfo = ref<LoginData>()

    const setToken = (value: string) => {
      token.value = value
    }

    const setUserInfo = (value: LoginData) => {
      userInfo.value = value
    }

    const removeToken = () => {
      token.value = ''
    }

    const removeUserInfo = () => {
      userInfo.value = undefined
    }

    return { token, setToken, removeToken, userInfo, setUserInfo, removeUserInfo }
  },
  {
    persist: {
      paths: ['token', 'userInfo'],
    },
  }
)
